//$(function(){
function initData(){
	var isNew = $('#isNew').val();
	if(isNew == "02"){//信息修改
		findLogisInfoAjax.send();
	}else{//新增
		var vector = $("#logisVector").val();
		//将客户填写信息写入
		if(vector == "01"){//公司至客户
			$('input[name="receiverName"]').val($("#name").val());
			$('input[name="receiverPhone"]').val($("#phone").val());
			$('input[name="receiverAddr"]').val($("#addr").val());
			$('textarea[name="receiverRemark"]').val($("#remark").val());
		}
	}
}
//});
function vectorOnChange(){
	var vector = $("#logisVector").val();
	if(vector == "01"){//公司至客户
		$('input[name="receiverName"]').val($("#name").val());
		$('input[name="receiverPhone"]').val($("#phone").val());
		$('input[name="receiverAddr"]').val($("#addr").val());
		$('textarea[name="receiverRemark"]').val($("#remark").val());
	}else{
		$('input[name="receiverName"]').val('');
		$('input[name="receiverPhone"]').val('');
		$('input[name="receiverAddr"]').val('');
		$('textarea[name="receiverRemark"]').val('');
	}
}
function findInfoSucc(re){
	if(re.success || re.success == 'true'){
		$("#logisEditFrm").autofill(re.info);
		$('#sysRemarkHis').html(re.info.sysRemark);
		$("#name").val(re.info.receiverName);
		$("#phone").val(re.info.receiverPhone);
		$("#addr").val(re.info.receiverAddr);
		$("#remark").val(re.info.receiverRemark);
	}else{
		$.messager.error("查询物流信息失败")
	}
}
//保存信息
function saveLogis(){
	//检查数据
	if($('input[name="receiverName"]').val().length == 0){
		MsgBox.warn("请输入收件人姓名", "提示", function(){
			$('input[name="receiverName"]')[0].focus();
		})
	}else if($('input[name="receiverName"]').val().length > 32){
		MsgBox.warn("收件人姓名应不超过32字", "提示", function(){
			$('input[name="receiverName"]')[0].focus();
		})
	}else if($('input[name="receiverPhone"]').val().length == 0){
		MsgBox.warn("请输入收件人电话", "提示", function(){
			$('input[name="receiverPhone"]')[0].focus();
		})
	}else if(!checkPhone($('input[name="receiverPhone"]').val())){
		MsgBox.warn("请输入正确的收件人电话", "提示", function(){
			$('input[name="receiverPhone"]')[0].focus();
		})
	}else if($('input[name="receiverPhone"]').val().length > 20){
		MsgBox.warn("收件人电话长度应不超过20", "提示", function(){
			$('input[name="receiverPhone"]')[0].focus();
		})
	}else if($('input[name="receiverAddr"]').val().length == 0){
		MsgBox.warn("请输入收件人地址", "提示", function(){
			$('input[name="receiverAddr"]')[0].focus();
		})
	}else if($('input[name="receiverAddr"]').val().length > 150){
		MsgBox.warn("收件人地址应小于150字", "提示", function(){
			$('input[name="receiverAddr"]')[0].focus();
		})
	}else if($('textarea[name="receiverRemark"]').val().length > 250){
		MsgBox.warn("收件备注应小于250字", "提示", function(){
			$('textarea[name="receiverRemark"]')[0].focus();
		})
	}else if($('input[name="logisCompany"]').val().length == 0){
		MsgBox.warn("请输入物流公司名称", "提示", function(){
			$('input[name="logisCompany"]')[0].focus();
		})
	}else if($('input[name="logisCompany"]').val().length > 25){
		MsgBox.warn("物流公司名称长度应小于25", "提示", function(){
			$('input[name="logisCompany"]')[0].focus();
		})
	}else if($('input[name="logisNo"]').val().length == 0){
		MsgBox.warn("请输入物流单号", "提示", function(){
			$('input[name="logisNo"]')[0].focus();
		})
	}else if($('input[name="logisNo"]').val().length > 50){
		MsgBox.warn("物流单号长度应小于50", "提示", function(){
			$('input[name="logisNo"]')[0].focus();
		})
	}else if($('input[name="consignorName"]').val().length == 0){
		MsgBox.warn("请输入发货人姓名", "提示", function(){
			$('input[name="consignorName"]')[0].focus();
		})
	}else if($('input[name="consignorName"]').val().length > 32){
		MsgBox.warn("发货人姓名应小于32字", "提示", function(){
			$('input[name="consignorName"]')[0].focus();
		})
	}else if($('input[name="consignorPhone"]').val().length == 0){
		MsgBox.warn("请输入发货人电话", "提示", function(){
			$('input[name="consignorPhone"]')[0].focus();
		})
	}else if(!checkPhone($('input[name="consignorPhone"]').val())){
		MsgBox.warn("请输入正确的发件人电话", "提示", function(){
			$('input[name="consignorPhone"]')[0].focus();
		})
	}else if($('input[name="consignorPhone"]').val().length > 20){
		MsgBox.warn("发货人电话长度应小于20", "提示", function(){
			$('input[name="consignorPhone"]')[0].focus();
		})
	}else if($('input[name="consignorAddr"]').val().length == 0){
		MsgBox.warn("请输入发货地址", "提示", function(){
			$('input[name="consignorAddr"]')[0].focus();
		})
	}else if($('input[name="consignorAddr"]').val().length > 150){
		MsgBox.warn("发货地址应小于150字", "提示", function(){
			$('input[name="consignorAddr"]')[0].focus();
		})
	}else if($('input[name="consignorTime"]').val().length == 0){
		MsgBox.warn("请选择发货时间", "提示", function(){
			$('input[name="consignorTime"]')[0].focus();
		})
	}else if($('#sysRemarkNew').val().length == 0){
		MsgBox.warn("请填写系统备注", "提示", function(){
			$('#sysRemarkNew')[0].focus();
		})
	}else{
		var txt = $('#isNew').val()=='01'?"确认新增此物流信息":"确认修改此物流信息";
		MsgBox.confirm(txt, "提示", function(){
			var data = $("#logisEditFrm").serializeObject();
			if(data.consignorTime != null && data.consignorTime.length > 0){
				data.consignorTime = data.consignorTime+":00";
			}
			if(data.receiverTime != null && data.receiverTime.length > 0){
				data.receiverTime = data.receiverTime+":00";
			}
			data.sysRemark = data.sysRemarkNew;
			editLogisAjax.setData(data);
			editLogisAjax.send();
		});
	}
}
function editLogisSucc(re){
	var msg = $('#isNew').val()=='01'?"新增此物流信息":"修改此物流信息";
	if(re.success || re.success == 'true'){
		$.messager.success(msg+"成功");
		refreshLogis();
		setTimeout("closePage()", 2000);
	}else{
		$.messager.error(msg+"失败");
	}
}
function closePage(){
	$('#closeCurr').click();
}
/**
 * 校验手机号
 * @param phone
 * @returns
 */
function checkPhone(phone) {
	if(phone == null || phone.length == 0){
		return false;
	}
	phone = phone.replace('-','');
	var reg = /^[0-9]*$/;
	return reg.test(phone);
}